package model.market;


//AMLOW: sack off the buy/sell thing as it isnt used.. only important that there is a trade.
public class Execution {

	Trade buy;
	Trade sell;
	int quantity;
	double price;
	int period;
	
	public int getPeriod(){
		return period;
	}
	
	
	public Execution(int period,Trade buy, Trade sell, int quantity) {
		super();
		this.period=period;
		this.buy = buy;
		this.sell = sell;
		if(quantity<0){
			throw new RuntimeException("Negative quantity? "+quantity);
		}
		this.quantity = quantity;
		
		
		//AM: trades can be null if trading with dealer.
		if(buy!=null){
			buy.addExecution(this);
		}
		if(sell!=null){
			sell.addExecution(this);
		}
	}
	
	//AM: this is needed because we dont know on execution what the price will be..
	public void setPrice(double price){
		if(Double.isNaN(price)){
			throw new RuntimeException("Price is NaN?");
		}
		this.price=price;
	}
	
	public Trade getBuy() {
		return buy;
	}
	
	public double getPrice() {
		return price;
	}
	
	public int getQuantity() {
		if(quantity<0){
			throw new RuntimeException("Trade quantity negative? "+quantity);
		}
		return quantity;
	}
	
	public Trade getSell() {
		return sell;
	}
	
	
}
